# _*_ coding: UTF-8 _*_
# @Time     : 2021/10/26 15:43
# @Author   : yangshuaishuai
# @Site     : http://www.hzdledu.cn/
# @File     : c10s1_文件操作.py
# @Software : PyCharm
# 打开/创建文件
# def foo1():
#     file1 = open('./test1.txt',mode='r',encoding='utf8')
#     #file2 = open(r'D:\PYwordspace\hz_t2\c10\test1.txt')
#     #关闭
#     file1.close()
#
#
def foo2():
    # with-open
    with open('./score1.txt', mode='r', encoding='utf8')as file:
        # 1.read():读取整个文件或指定个数的字符串
        str1 = file.read()
        print(str1)


#
#
# def foo3():
#     #with-open
#     with open('./test1.txt',mode='r',encoding='utf8')as file:
#         #2.readline():读取文件中一行
#         str1 = file.readline()
#         print(str1)

# 文件的写入
def foo5():
    with open('./test2.txt', 'w', encoding='utf')as file:
        str1 = '犇\n汇智动力\n2021'
        # write():将字符串内容写入文件
        file.write(str1)



# 将字符串列表写入文件
def foo6():
    with open('./test3.txt', 'w', encoding='utf')as file:
        list1 = '码\n汇智动力\n2031'
        file.writelines(list1)


def foo4():
    # with-open
    with open('./test1.txt', mode='r', encoding='utf8')as file:
        # 1.readlines():读取文件中的所有行，放入一个列表
        list1 = file.readlines()
        print(list1)


if __name__ == '__main__':
    #     foo1()
    foo2()
#     foo3()
#   foo4()
#     foo6()
#     foo5()
